﻿@{
    ViewBag.Title = "Form";
    Layout = "~/Views/Shared/_Form.cshtml";
}

<script>
    var keyValue = $.request("keyValue");
    $(function () {
        initControl();
        if (!!keyValue) {
            $.ajax({
                url: "/SystemManage/user/GetFormJson",
                data: { keyValue: keyValue },
                dataType: "json",
                async: false,
                success: function (data) {
                    $("#form1").formSerialize(data);
                    $("#password").attr('disabled', 'disabled');
                    //$("#password").val("******").attr('disabled', 'disabled');
                }
            });
        }
    });
    
    function initControl() {
        $('#wizard').wizard().on('change', function (e, data) {
            var $finish = $("#btn_finish");
            var $next = $("#btn_next");
            if (data.direction == "next") {
                switch (data.step) {
                    case 1:
                        if (!$('#form1').formValid()) {
                            return false;
                        }
                        break;
                    case 2:
                        if (!$('#form1').formValid()) {
                            return false;
                        }
                        $finish.show();
                        $next.hide();
                        break;
                    default:
                        break;
                }
            } else {
                $finish.hide();
                $next.show();
            }
        });
      $("#rolelist").treeview({
            height: 444,
            showcheck: true,
            url: "/SystemManage/User/getRolelist",
            param: { userId: keyValue }
        });
        $("#grouplist").treeview({
            height: 444,
            showcheck: true,
            url: "/SystemManage/User/getGrouplist",
            param: { userid : keyValue }
        });
}

    function submitForm() {
        if (!$('#form1').formValid()) {
            return false;
        }
        var postData = $("#form1").formSerialize();
        roleData = String($("#rolelist").getCheckedNodes());
        var groupdata = [];
        groupdata = String($("#grouplist").getCheckedNodes());
        $.submitForm({
            url: "/SystemManage/user/SubmitForm?keyValue=" + keyValue + "&rolelistIds=" + roleData + "&grouplistIds=" + groupdata,
            param: postData,
            success: function () {
                $.currentWindow().$("#gridList").trigger("reloadGrid");
            }
        })
    }

    //$(document).ready(function () {
    //    $("a[name='btn_next']").click(function () {
    //        Ext.Msg.confirm(

    //            )
    //    })
 

    

</script>

<form id="form1">
    <div class="widget-body">
        <div id="wizard" class="wizard" data-target="#wizard-steps" style="border-left: none; border-top: none; border-right: none;">
            <ul class="steps">
                <li data-target="#step-1" class="active"><span class="step">1</span>基本信息<span class="chevron"></span></li>
                <li data-target="#step-2"><span class="step">2</span>角色<span class="chevron"></span></li>
                <li data-target="#step-3"><span class="step">3</span>分组<span class="chevron"></span></li>
            </ul>
        </div>
        <div class="step-content" id="wizard-steps" style="border-left: none; border-bottom: none; border-right: none;">
            <div class="step-pane active" id="step-1" style="margin: 10px; margin-bottom: 0px;">
               <div class="panel panel-default">
                   <div class="panel-body" style="width: 98%;">
                        <table class="form">
                            <tr>
                                <th class="formTitle">姓名<span style="color:red;">*</span></th>
                                <td class="formValue">
                                    <input id="username" name="username" type="text" class="form-control required" placeholder="请输入用户名称" />
                                </td>
                            </tr>
                            <tr>
                                <th class="formTitle">密码<span style="color:red;">*</span></th>
                                <td class="formValue">
                                    <input id="password" name="password" type="text" class="form-control required" placeholder="请输入用户密码" value="123456"/>
                                </td>
                            </tr>
                        </table>
                    </div>
                </div>
            </div>
            <div class="step-pane" id="step-2">
                <div id="rolelist"></div>
            </div>
            <div class="step-pane" id="step-3">
                <div id="grouplist"></div>
            </div>
        </div>
        <div class="form-button" id="wizard-actions">
            <a id="btn_last" disabled class="btn btn-default btn-prev">上一步</a>
            <a id="btn_next" class="btn btn-default btn-next">下一步</a>
            <a id="btn_finish" class="btn btn-default" style="display: none;" onclick="submitForm()">完成</a>
        </div>
    </div>
</form>